package com.fengye.algorithms.other;

/**
 * @Author fengye
 * @Date 2023/4/9 9:09
 **/
public class GysMain {
    public static void main(String[] args) {
        System.out.println(getBigGys1(18,12));
        System.out.println(getBigGys2(18,12));
    }

    public static int getBigGys2(int a, int b) {
        if(a == b) {
            return a;
        }
        // 保证a > b
        if(a<b) {
            int t = a;
            a = b;
            b = t;
        }
        int m=0;
        // 处理偶数的情况
        if((a & 1) == 0 && (b & 1) == 0) {
            a /= 2;
            b /= 2;
            m++;
        }

        int r = 0;
        while (true) {
            r = a - b;
            if(r == b) {
                break;
            }
            a = Math.max(b, r);
            b = Math.min(b,r);
        }

        return (int)Math.pow(2, m) * r;
    }

    public static int getBigGys1(int a, int b) {
        // 保证a > b
        if(a<b) {
            int t = a;
            a = b;
            b = t;
        }
        while (b % a != 0) {
            int t = b % a;
            b = a;
            a = t;
        }

        return a;
    }
}
